﻿using System;
using System.ServiceModel.Web;

namespace MugenInjection.Wcf.WebServiceHostImpl
{
    /// <summary>
    /// A service host that uses MugenInjection to create the service instances.
    /// </summary>
    public abstract class MugenInjectionWebServiceHostBase : WebServiceHost
    {
        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="MugenInjectionWebServiceHostBase"/> class.
        /// </summary>
        protected MugenInjectionWebServiceHostBase()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MugenInjectionWebServiceHostBase"/> class with the specified service type and base address.
        /// </summary>
        /// <param name="serviceType">The service type.</param><param name="baseAddresses">The base address of the service.</param>
        protected MugenInjectionWebServiceHostBase(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MugenInjectionWebServiceHostBase"/> class with the specified singleton server instance and base address.
        /// </summary>
        /// <param name="singletonInstance">A service instance to be used as the singleton instance.</param><param name="baseAddresses">The base address of the service.</param>
        protected MugenInjectionWebServiceHostBase(object singletonInstance, params Uri[] baseAddresses)
            : base(singletonInstance, baseAddresses)
        {
        }

        #endregion

        #region Overrides of ServiceHostBase

        /// <summary>
        /// Called when the <see cref="T:System.ServiceModel.Web.WebServiceHost"/> instance opens.
        /// </summary>
        protected override void OnOpening()
        {
            WcfConfigExtension.InitializeServiceHostOnOpening(this);
            base.OnOpening();
        }

        /// <summary>
        /// Initializes the runtime for the service host.
        /// </summary>
        /// <exception cref="T:System.InvalidOperationException">The description of the service hosted is null.</exception>
        protected override void InitializeRuntime()
        {
            base.InitializeRuntime();
            WcfConfigExtension.InitializeServiceHostOnInitializeRuntime(this);
        }

        #endregion
    }
}